/* EDTQ: expire date & time quantum */

#ifndef USER_PASSWORD_DYNAMIC_EDTQ_H
#define USER_PASSWORD_DYNAMIC_EDTQ_H

#ifndef USER_PASSWORD_DYNAMIC_H
#error "include user_password_dynamic.h instead!"
#endif

#ifdef GKT_CONFIG_USER_PASSWORD_DYNAMIC_EDTQ_ENABLE
#define USER_DYNPWD_EDTQ_ENABLE	\
	GKT_CONFIG_USER_PASSWORD_DYNAMIC_EDTQ_ENABLE
#else
#define USER_DYNPWD_EDTQ_ENABLE	0
#endif

#define USER_DYNPWD_EDTQ_ED_YEAR_OFFSET_MAX	15
#define USER_DYNPWD_EDTQ_TAG_VALUE	0x2A	/* 0b101010 */

#define USER_DYNPWD_EDTQ_ST_HOUR_BITS	5
#define USER_DYNPWD_EDTQ_ET_HOUR_BITS	5
#define USER_DYNPWD_EDTQ_ED_DAY_BITS	5
#define USER_DYNPWD_EDTQ_ED_MONTH_BITS	4
#define USER_DYNPWD_EDTQ_ED_YEAR_OFFSET_BITS	4
#define USER_DYNPWD_EDTQ_TAG_BITS	6

#define USER_DYNPWD_EDTQ_FIELD_MASK(FIELD)	\
	((1U << USER_DYNPWD_EDTQ_##FIELD##_BITS) - 1)

#define USER_DYNPWD_EDTQ_ST_HOUR_SHIFT	\
	(USER_DYNPWD_GENERAL_SHIFT + USER_DYNPWD_GENERAL_BITS)
#define USER_DYNPWD_EDTQ_ET_HOUR_SHIFT	\
	(USER_DYNPWD_EDTQ_ST_HOUR_SHIFT + USER_DYNPWD_EDTQ_ST_HOUR_BITS)
#define USER_DYNPWD_EDTQ_ED_DAY_SHIFT	\
	(USER_DYNPWD_EDTQ_ET_HOUR_SHIFT + USER_DYNPWD_EDTQ_ET_HOUR_BITS)
#define USER_DYNPWD_EDTQ_ED_MONTH_SHIFT	\
	(USER_DYNPWD_EDTQ_ED_DAY_SHIFT + USER_DYNPWD_EDTQ_ED_DAY_BITS)
#define USER_DYNPWD_EDTQ_ED_YEAR_OFFSET_SHIFT	\
	(USER_DYNPWD_EDTQ_ED_MONTH_SHIFT + USER_DYNPWD_EDTQ_ED_MONTH_BITS)
#define USER_DYNPWD_EDTQ_TAG_SHIFT	\
	(USER_DYNPWD_EDTQ_ED_YEAR_OFFSET_SHIFT + USER_DYNPWD_EDTQ_ED_YEAR_OFFSET_BITS)

#define USER_DYNPWD_EDTQ_TOTAL_BITS	\
	(USER_DYNPWD_EDTQ_TAG_SHIFT + USER_DYNPWD_EDTQ_TAG_BITS)
#define USER_DYNPWD_EDTQ_TOTAL_UNITS	\
	((USER_DYNPWD_EDTQ_TOTAL_BITS + 3) >> 2)

#define USER_DYNPWD_EDTQ_FIELD(value, FIELD)	\
	(((value) >> USER_DYNPWD_EDTQ_##FIELD##_SHIFT) \
		& USER_DYNPWD_EDTQ_FIELD_MASK(FIELD))
	
typedef struct _user_dynpwd_edtq_data {
	uint16_t	st_hour;
	uint16_t	et_hour;
	gkt_date_u	expire_date;
} user_dynpwd_edtq_data_s;

typedef struct _user_dynpwd_edtq_item_data {
	uint16_t	st_hour;
	uint16_t	et_hour;
	uint32_t	expire_date;
} user_dynpwd_edtq_item_data_s;

#if USER_DYNPWD_EDTQ_ENABLE
int user_dynpwd_EDTQ_retrieve(user_dynpwd_data_s *data,
				uint32_t *values);
int user_dynpwd_EDTQ_verify(user_dynpwd_data_s *data,
				uint32_t admin_item_index);
#else
#define user_dynpwd_EDTQ_retrieve	NULL
#define user_dynpwd_EDTQ_verify	NULL
#endif

#endif	/* USER_PASSWORD_DYNAMIC_EDTQ_H */

